package com.hxht.storage.server.service.quartz.job;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerContext;
import org.quartz.SchedulerException;

import com.hxht.storage.server.service.NvrDeviceService;

public class NvrScanJob extends BaseNvrJob {

	private static Logger quartzLogger = Logger.getLogger(NvrScanJob.class);

	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {

		// 获取JobExecutionContext中的service对象
		SchedulerContext skedCtx;
		try {
			skedCtx = context.getScheduler().getContext();
			// 获取SchedulerContext中的service
			// 这里的service就是通过配置文件 配置的
			nvrDeviceService = (NvrDeviceService) skedCtx
					.get("nvrDeviceService");
			boolean isOnline = nvrDeviceService.scanNvr(sn);

			// nvr不在线时，记录日志
			if (!isOnline)
				quartzLogger.warn( sn + " is not online!");
		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			quartzLogger.error("nvr scan job error!", e);
		}
	}
}
